using System.Linq;
using Abp.AspNetCore.Mvc.Controllers;
using Abp.Domain.Repositories;
using Batman.Core;
using Batman.Jianbei.Forum.Core.Consts;
using Batman.Jianbei.Forum.Core.Domains.Dicts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

[Area(RouteNames.Forum)]
public class SelectionController : AbpController
{
    public IRepository<Topic, string> TopicRepo { get; set; }

    public IActionResult Topic()
    {
        var query = TopicRepo.GetQuery().Where(t => !t.IsDeleted).Include(t => t.Partition).AsQueryable();

        query = query.OrderByDescending(t => t.Sort).ThenByDescending(t => t.CreateAt).AsQueryable();

        var items = query.Select(t => new TopicSelectionResponse
        {
            PartitionId = t.PartitionId,
            PartitionName = t.Partition.Name,
            TopicId = t.Id,
            TopicName = t.Name
        }).ToList();

        return Json(items);
    }
}